package com.wlyuan.open.scanner.domain.transport;

import com.wlyuan.open.scanner.utils.JsonUtils;
import com.wlyuan.open.scanner.utils.mappings.BaseMapping;
import org.mapstruct.*;
import org.mapstruct.factory.Mappers;

/**
 * @author lijing
 * @description
 */
public class TransportRelationConvert {

    private static final Convert CONVERT = Mappers.getMapper(Convert.class);

    @Mapper
    public interface Convert {

        @Mappings({
                @Mapping(source = "downTransportId", target = "sourceKey"),
                @Mapping(source = "upTransportId", target = "upTransportId"),
                @Mapping(source = "downTransportId", target = "downTransportId"),
                @Mapping(source = "tenantId", target = "tenantId"),
        })
        @BaseMapping
        TransportIdRelation convert(Long downTransportId, Long upTransportId, Long tenantId);

        @AfterMapping
        default void after(@MappingTarget TransportIdRelation target, Long downTransportId, Long upTransportId) {
            target.setRaw(JsonUtils.withNullJson(target));
        }
    }

    public static TransportIdRelation convert(Long downTransportId, Long upTransportId, Long tenantId) {
        return CONVERT.convert(downTransportId, upTransportId, tenantId);
    }
}
